package com.example.dessertstoressm.domain;

import java.io.BufferedWriter;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Log {
    public final static int OUT_CONSOLE=1;
    public final static int DEBUG_LEVEL=0;
    protected static int level=DEBUG_LEVEL;// 输出的级别开关，高于指定级别的输出
    protected static int out=OUT_CONSOLE; //输出模式，输出到控制台，文件或者都输出

    public static String logdir="log";    // 保存日志文件的目录
    protected static BufferedWriter bw =null;
    protected static String currentDate = "";
    protected static Date data=null;
    protected static StringBuilder bb=new StringBuilder();
    protected static String marsk=" [ERROE] ";


    //输出的是一些时间信息
    synchronized public static String log(Object ...s) {
        bb.delete(0, bb.length());

        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());

        bb.append(formatter.format(date));
        //一个效果，上面不行的话再用下面的
        //bb.append(time());
        bb.append(marsk);

        bb.append("  ");

        for(Object str : s) {
            bb.append(str);
            bb.append(" ");
        }
        return bb.toString();
    }

    public static String logInfomation(Object ...s){
        marsk = " ";
        return log(s);
    }


    protected static String time() {
        data = new Date();
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(data);
    }

}
